package com.cndw.kungfu.model.main;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.stereotype.Component;
import com.cndw.kungfu.domain.Livery;
import com.cndw.kungfu.domain.Union;
import com.cndw.kungfu.event.once.AiUndercityTask;
import com.cndw.kungfu.model.activity.Quiz;
import com.cndw.kungfu.model.battle.Battle;
import com.cndw.kungfu.model.battle.Team;
import com.cndw.kungfu.model.disciple.PlayerMartial;
import com.cndw.kungfu.model.goods.PlayerTrade;
import com.cndw.kungfu.model.skill.PlayerSkill;
import com.cndw.kungfu.model.task.DartTask;

/**
 * 记录某些模块运行产生的数据
 * 
 * @author fantadust
 * @date 2011-4-29 下午04:37:50
 */
@Component
public class DataServer {

	/**
	 * 战斗对象存储
	 */
	private static final Map<Integer, Battle> battleMap = new ConcurrentHashMap<Integer, Battle>();
	/**
	 * 帮派对象
	 */
	private static final ConcurrentHashMap<Integer, Union> unioinMap = new ConcurrentHashMap<Integer, Union>();

	private static final ConcurrentHashMap<String, Object> businessAllMap = new ConcurrentHashMap<String, Object>();

	private static final ConcurrentHashMap<Long, PlayerSkill> playerSkillMap = new ConcurrentHashMap<Long, PlayerSkill>();
	/**
	 * 玩家门派数据存储
	 */
	private static final ConcurrentHashMap<Long, PlayerMartial> playerMartialMap = new ConcurrentHashMap<Long, PlayerMartial>();
	/**
	 * 系统交易存储
	 */
	private static final ConcurrentHashMap<Long, PlayerTrade> playerTradeMap = new ConcurrentHashMap<Long, PlayerTrade>();
	
	/**
	 *玩家答题数据 
	 */
	private static final Map<Long, Quiz> quizMap = new ConcurrentHashMap<Long, Quiz>();
	/**
	 * 队伍模型
	 */
	private static final Map<Integer, Team> teamMap = new ConcurrentHashMap<Integer, Team>();
	
	/**
	 * 侍从信息
	 */
	private static final Map<Long, Livery> liveryMap = new ConcurrentHashMap<Long, Livery>();
	/**
	 * 副本挂机对象
	 */
	private static final Map<Long, AiUndercityTask> aiTaskMap = new ConcurrentHashMap<Long, AiUndercityTask>();
	
	private static final Map<Long, DartTask> dartTaskMap = new ConcurrentHashMap<Long, DartTask>();
	
	public Map<Integer, Battle> getBattleMap() {
		return battleMap;
	}

	public ConcurrentHashMap<Integer, Union> getUnionMap() {
		return unioinMap;
	}

	public ConcurrentHashMap<String, Object> getBusinessAllMap() {
		return businessAllMap;
	}

	public ConcurrentHashMap<Long, PlayerSkill> getPlayerSkillMap() {
		return playerSkillMap;
	}

	public ConcurrentHashMap<Long, PlayerMartial> getPlayerMartialMap() {
		return playerMartialMap;
	}

	public ConcurrentHashMap<Long, PlayerTrade> getPlayerTradeMap() {
		return playerTradeMap;
	}

	public Map<Long, Quiz> getQuizmap() {
		return quizMap;
	}
	
	public Livery getLivery(long playerId){
		return liveryMap.get(playerId);
	}
	
	public void putLivery(long playerId, Livery livery){
		liveryMap.put(playerId, livery);
	}
	
	public void removeLivery(long playerId){
		liveryMap.remove(playerId);
	}
	
	public Collection<Livery> liveries(){
		return liveryMap.values();
	}
	
	public Team getTeam(int id){
		return teamMap.get(id);
	}
	public void putTeam(Team team){
		if (team.getId() > 0) {
			teamMap.put(team.getId(), team);
		}
	}
	public void teamRemove(int id ){
		teamMap.remove(id);
	}
	public Collection<Team> getTeams(){
		return teamMap.values();
	}
	
	public void aiTaskAdd(long playerId,AiUndercityTask aiTask){
		aiTaskMap.put(playerId, aiTask);
	}
	public void aiTaskRemove(long playerId){
		aiTaskMap.remove(playerId);
	}
	public AiUndercityTask aiTaskGet(long playerId){
		return aiTaskMap.get(playerId);
	}
	
	public void dartTaskAdd(DartTask dartTask){
		dartTaskMap.put(dartTask.getPlayerId(), dartTask);
	}
	public void dartTaskRemove(long playerId){
		dartTaskMap.remove(playerId);
	}
	public DartTask dartTaskGet(long playerId){
		return dartTaskMap.get(playerId);
	}
	public Collection<DartTask> dartTasks(){
		return dartTaskMap.values();
	}
	
	
	public Map<String, Object> info(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("battle.size", battleMap.size());
		map.put("union.size", unioinMap.size());
		map.put("skill.size", playerSkillMap.size());
		map.put("martial.size", playerMartialMap.size());
		map.put("trade.size", playerTradeMap.size());
		map.put("quiz.size", quizMap.size());
		map.put("team.size", teamMap.size());	
		map.put("livery.size", liveryMap.size());	
		map.put("aiTask.size", aiTaskMap.size());
		map.put("dartTask.size", dartTaskMap.size());		
		return map;
	}
}
